import React, { Component } from "react";
import { List, Toast } from "antd-mobile";
import MainLayout from "@/component/mainLayout/mainLayout";
import { channelCode } from "@/config/Config";
import XHQBConfig from "@/config/XHQBConfig";
import yhTools from "@/tools/yh";
import "./setup.scss";
const Item = List.Item;

class Setup extends Component {
	constructor(props) {
		super(props);
		this.state = {
			phone: "",
			isLoad: false,
			isReal: false
		};
	}
	componentDidMount() {
		let phonenumber = JSON.parse(window.sessionStorage.getItem("phone"));
		this.setState({
			phone: phonenumber
		});
		this.init();
	}
	init = () => {
		Toast.loading("加载中...", 100);
		let objs = {
			url: XHQBConfig.queryMemberInfo,
			params: {
				channelCode: channelCode
			},
			_alertShow: false
		};
		let _that = this;
		yhTools.request(objs).then(res => {
			let { realName } = res.data;
			if (res.code === "0") {
				Toast.hide();
				_that.setState({
					isReal: !realName,
					isLoad: true
				});
			} else {
				Toast.info(res.message, 2);
			}
		});
	};
	goToforget() {
		this.props.history.push({
			pathname: "/forgetpassword",
			state: this.state.phone
		});
	}
	render() {
		const { isReal, isLoad } = this.state;
		const _pageParams = {
			header: {
				title: "设置"
			},
			history: this.props.history,
			cacheLifecycles: this.props.cacheLifecycles
		};
		return (
			<MainLayout pageParams={_pageParams}>
				<div className="setup-page-content">
					<List className="my-list">
						<Item
							arrow="horizontal"
							extra={
								isLoad ? (
									isReal ? (
										<span className="red">去实名</span>
									) : (
										"已实名"
									)
								) : (
									""
								)
							}
							onClick={() => {
								if (isLoad) {
									if (isReal) {
										this.props.history.push("/xhqbrealnameauth");
									} else {
										this.props.history.push("/realNameInfor");
									}
								}
							}}
						>
							实名认证
						</Item>
						<Item
							arrow="horizontal"
							onClick={() => {
								this.props.history.push("/paymentpassword");
							}}
						>
							修改支付密码
						</Item>
						<Item
							arrow="horizontal"
							onClick={() => {
								this.goToforget();
							}}
						>
							找回支付密码
						</Item>
						<Item
							arrow="horizontal"
							onClick={() => {
								this.props.history.push("/myAgreement");
							}}
						>
							我的协议
						</Item>
					</List>
				</div>
			</MainLayout>
		);
	}
}
export default Setup;
